package gamePack.entities;

import gamePack.Controller;
import gamePack.Game;
import gamePack.Physics;
import gamePack.gfx.Animation;
import gamePack.gfx.ImageManager;

import java.awt.Graphics;
import java.awt.Rectangle;
import java.util.Random;

public class Enemy extends GameObject implements EntityB {

	private Game game;
	private Controller controler;
	private Physics fisica;

	private Random r = new Random();
	private int speed = r.nextInt(3) + 1;
	private ImageManager im;
	private Animation enemyAnim;

	public Enemy(int x, int y, Game game, Controller c, ImageManager im,
			Physics fisica) {
		super(x, y);
		this.game = game;
		this.controler = c;
		this.im = im;
		this.fisica = fisica;
		enemyAnim = new Animation(im.getEnemy(), 500);
	}

	public void tick() {

		if (y > (game.getHeight() - 32)) {
			speed = r.nextInt(3) + 1;
			x = r.nextInt(game.getWidth() - 32);
			y = -10;
		}

		if (fisica.Collision(this, game.getEntA())) {
			game.aBorrarEntB(this);
			controler.addEntity(new PowerUp(x, y, game, controler, im, fisica));
			game.setEnemy_killed(game.getEnemy_killed() + 1);
			game.aumentarScore(100);
		}
		y = y + speed;

	}

	public void render(Graphics g) {
		enemyAnim.render(g, x, y, game.getTileSize(), game.getTileSize());
	}

	public Rectangle getBounds() {
		return new Rectangle(x, y, 32, 32);
	}

	public int getX() {
		return x;
	}

	public int getY() {
		return y;
	}

	public void setX(int valor) {
		x = valor;
	}

	public void setY(int valor) {
		y = valor;
	}
}
